from PyQt5.QtSql import QSqlDatabase, QSqlQuery, QSqlTableModel
from datetime import date
import getpath
import os
import logging
class Db():
    def __init__(self):
        self.init_db()
    def init_db(self):
        """
        init_db()
        Initializes the database.
        If tables "books" and "authors" are already in the database, do nothing.
        Return value: None or raises ValueError
        The error value is the QtSql error instance.
        """
        self.db = QSqlDatabase.addDatabase("QSQLITE")
        p = os.path.join(getpath.getpath(), "data.sqlite")
        db.setDatabaseName(p)
    def sql_cmd(self,cmd):
        self.q.prepare(cmd)
        logging.info(cmd)
        r = self.q.exec_()
        self.q.finish()
        if not r:
            logging.info(self.q.lastError())
    def test(self):
        cmd="""insert into STDS (
    sampleid,mass,volume,xishi,'C_','Si','Mn_','P_','S_','Cr_','Mo_','Ni_','Cu_','V_','Nb_','W_','Co_','Ti_','Al_','B_','N_','As_','Sn_','Pb_','Sb_','Zr_','Ca_','Ta_','Mg_') values('BS M-50','0','0','','0.834','0.205','0.244','0.0066','0.0009','4.28','4.29','0.074','0.064','0.99','0.0008','0.0052','0.0151','0.0018','0.073','0.0001','0.0057','0.0035','None','None','0.0006','0.0006','None','None','0.0002')"""
        self.sql_cmd(cmd)
if __name__=="__main__":
    init_db()
    exec_one()